package goover.unit05;

import java.sql.*;

public class JdbcDemo01 {
    public static void main(String[] args){
        Connection conn = null;
        Statement set = null;
        ResultSet rst = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/jdbc";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url,user,password);
            String sql = "select * from account";
            set = conn.createStatement();
            rst = set.executeQuery(sql);
            while (rst.next()){
                System.out.println("" + rst.getInt("id") + rst.getString("name") + rst.getString("balance"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            if(rst != null){
                try {
                    rst.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(set != null){
                try {
                    set.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }
}
